<?php

include '../_mysql.php';
include '../_settings.php';
include '../_functions.php';

$json_result = array();

$type = $_POST["type"];
$email = $_POST['email'];

$json_result["success"] = false;
$json_result["message"] = "Can't request to server.";

if ($type == "forget_username") {	
	$result = safe_query("SELECT * FROM ".PREFIX."user WHERE email = '".$email."' LIMIT 0 , 1");
	if (mysql_fetch_row($result)) {
		$json_result["success"] = true;
		$json_result["message"] = "<h4>Success!</h4><p>An email has been sent with instructions how to restore your password</p><p>If you haven't recieved the email within x hours please check your spam filter.</p>";
	} else {
		$json_result["success"] = false;
		$json_result["message"] = "<h4>There is no user with that email address.</h4>";
	}
} else {
	$result = safe_query("SELECT * FROM ".PREFIX."user WHERE email = '".$email."' OR username = '".$email."' LIMIT 0 , 1");
	if (mysql_fetch_row($result)) {
		$json_result["success"] = true;
		$json_result["message"] = "Success!<p>An email has been sent with instructions how to restore your password</p><p>If you haven't recieved the email within x hours please check your spam filter.</p>";
	} else {
		$json_result["success"] = false;
		$json_result["message"] = "There is no user with username or with that email address.";
	}
}

echo json_encode($json_result);

?>